from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
# chrome_options.add_argument('--disable-dev-shm-usage')


try:
    driver = webdriver.Chrome(chrome_options=chrome_options)
    driver.get('https://weixin.sogou.com/weixin?type=1&query=%E5%A4%AE%E8%A7%86%E7%BD%91&ie=utf8&s_from=input&_sug_=y&_sug_type_=')

    #sel = driver.find_element_by_css_selector('a[uigs=account_article_0]')
    #print (sel.get_attribute('href'))
    driver.get('https://mp.weixin.qq.com/s?src=11&timestamp=1644123906&ver=3603&signature=euxvqkuIUOx0MXUHVo18OxvAuf-LLLtwvYct65cGVqv74ihL7riSYC56xgSGncQXWyyfLesuBtMXkCDEsVUfVjFj-O5ODX3KDhBFACA1oQeRX8HArx0-XBEcAaSmIv87&new=1')
    
    
    sel = WebDriverWait(driver, 2).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, ".rich_media_area_primary"))
    )
    # sel = driver.find_element_by_css_selector('#js_article')
    imgs = sel.find_elements_by_tag_name("div img")
    for img in imgs:
        # print("-----------------------")
        try:
            src = img.get_attribute('data-src')
            time.sleep(0.5)
            if(src):
                print("<img src='"+src+"'/>")
        except:
            print("continue")
    print(sel.text)
finally:
    driver.close()
    driver.quit()
